--[[ 编码: JX-108-18 名称: 巨星任务-创建巨星出库作业 作者:HAN 日期:2025-1-29 级别:项目 函数: CreateOutOperation 功能: 根据巨星下发的出库任务创建巨星出库作业 -- 如果已经指定 end_loc 直接出库到这个位置,没有需要根据 终点区域分配一个货位 更改记录: --]] jx_base= require( "jx_base" ) wms_alg = require( "wms_base_algorithm" ) function CreateOutOperation ( strLuaDEID ) local nRet, strRetInfo local strUpdateSql, strCondition local jx_task = {} nRet, jx_task = m3.GetSysCurEditDataObj( strLuaDEID, "JX_Task" ) if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "获取【巨星任务】对象属性失败!"..jx_task ) end -- 获取作业起点 local start_loc, loc_code local end_loc local err_msg = '' loc_code = wms_wh.GetLocCodeByCNTR( strLuaDEID, jx_task.cntr_code ) if ( loc_code == '' ) then err_msg = '料箱没有绑定货位!' goto err_msg_process end nRet, start_loc = wms_wh.GetLocInfo( loc_code ) if ( nRet ~= 0 ) then err_msg = "获取货位'"..loc_code.."'信息失败!" goto err_msg_process end -- 获取作业终点 if ( jx_task.end_loc_code ~= '') then -- 接口已经确定了出库目标货位 nRet, end_loc = wms_wh.GetLocInfo( jx_task.end_loc_code ) if ( nRet ~= 0 ) then err_msg = "获取货位'"..jx_task.end_loc_code.."'信息失败!" goto err_msg_process end else -- 接口确定了出库区域 if ( jx_task.end_area_code == '' ) then err_msg = "出库任务没有指定出库目的库区" goto err_msg_process end local loc_list nRet, loc_list = wms_alg.GetAreaLocTaskNumber( strLuaDEID, jx_task.end_area_code ) if ( nRet ~= 0 ) then err_msg = "获取出库终点货位失败!"..loc_list goto err_msg_process end nRet, end_loc = wms_wh.GetLocInfo( loc_list[1].loc_code ) if ( nRet ~= 0 ) then err_msg = "获取货位'"..loc_list[1].loc_code.."'信息失败!" goto err_msg_process end end operation = m3.AllocObject(strLuaDEID,"Operation") operation.start_wh_code = start_loc.wh_code operation.start_area_code = start_loc.area_code operation.start_loc_code = start_loc.code operation.end_wh_code = end_loc.wh_code operation.end_area_code = end_loc.area_code operation.end_loc_code = end_loc.code operation.cntr_code = jx_task.cntr_code operation.op_type = wms_base.Get_nConst(strLuaDEID, "作业类型-出库") operation.op_def_name = "巨星出库" operation.bs_type = "巨星任务" operation.bs_no = jx_task.sour_no operation.source_sys = "巨星" nRet, operation = m3.CreateDataObj( strLuaDEID, operation ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), '创建【作业】失败!'..operation ) end -- N_B_STATE = 1 任务执行 strUpdateSql = "N_B_STATE = 1, S_OP_CODE = '"..operation.code.."'" strCondition = "S_SOURNO = '"..jx_task.sour_no.."'" nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "JX_Task", strCondition, strUpdateSql ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "更新【巨星任务】信息失败!"..strRetInfo ) end ::err_msg_process:: -- 4 表示任务执行失败 if ( err_msg ~= '' ) then strUpdateSql = "N_B_STATE = 4, S_RUN_ERR = '"..lua.FormatSQLString(err_msg).."'" strCondition = "S_SOURNO = '"..jx_task.sour_no.."'" nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "JX_Task", strCondition, strUpdateSql ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "更新【巨星任务】信息失败!"..strRetInfo ) end end end